﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace L
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DropDownList2.Items.Add("福建");
                DropDownList2.Items.Add("广东");
                DropDownList2.Items.Add("广西");
            }
        }

        protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        {
            string province = DropDownList2.SelectedValue;
            DropDownList3.Items.Clear();
            if (province == "福建")
            {
                DropDownList3.Items.Add("龙岩");
                DropDownList3.Items.Add("泉州");
                DropDownList3.Items.Add("福州");
            }
            else if (province == "广东")
            {
                DropDownList3.Items.Add("深圳");
                DropDownList3.Items.Add("东莞");
                DropDownList3.Items.Add("广州");
            }
            else
            {
                DropDownList3.Items.Add("北海");
                DropDownList3.Items.Add("桂林");
                DropDownList3.Items.Add("柳州");
            }

        }

        protected void Button1_Click(object sender, EventArgs e)
        {

            //设置一个变量
            string hobby = null;
            //遍历多选列表的选项集合
            for (int i = 0; i < hobbys.Items.Count; i++)
            {
                //判断该选项是否被选中
                if (hobbys.Items[i].Selected)
                {
                    //将被选中的选项添加到变量中
                    hobby += hobbys.Items[i] + " ";
                }
            }

            Button1.Text = $"用户名：{TextBox1.Text}，密码：{TextBox2.Text}，性别：{DropDownList1.SelectedValue}，爱好：{hobby}，籍贯：省  {DropDownList2.SelectedValue}  市  {DropDownList3.SelectedValue}，其它信息:{TextBox3.Text}";

            if (ful.HasFile)
            {
                string fileName = ful.FileName;
                if (fileName.EndsWith(".jpg") || fileName.EndsWith(".png") || fileName.EndsWith(".jpeg"))
                {
                    string url = Server.MapPath("/img/" + fileName);
                    ful.SaveAs(url);
                    Image1.ImageUrl = "/img/" + fileName;
                    Image1.Visible = true;
                }
            }

        }
    }
}